﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business.Menu;

public partial class UserControls_ucFirstMenu : System.Web.UI.UserControl
{
    /// <summary>
    /// 输出html
    /// </summary>
    protected string StrHtml { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UserId"] == null) return;
            var userId = Convert.ToString(Session["UserId"]);
            StrHtml = GetStrHtml(userId);
        }
    }

    private static string GetStrHtml(string userId)
    {
        var menu = new XtMenuOperation();
        var dtFirstMenu = menu.GenerateFirstMenu();
        var builder = new StringBuilder();
        builder.Append(" <ul class=\"nav\"> \r\n");
        dtFirstMenu.Rows.Cast<DataRow>().ToList().ForEach(row =>
        {
            if (!menu.IsExistChildMenu(row["firstmenuid"].ToString(), userId)) return;
            builder.Append("\t <li><a href=\"#\" > \r\n");
            builder.AppendFormat("\t <img src=\"{0}\"/><h2>{1}</h2> </a></li> \r\n", row["icon_url"].ToString(), row["menuname"].ToString());
        });
        builder.Append(" </ul>");
        return builder.ToString();
    }
}